import axios from 'axios'
import { getToken } from './auth'
import store from '@/store'

const service = axios.create({
    baseURL: process.env.BASE_API,
    timeout: 5000
})

service.interceptors.request.use(config => {
    if (store.getters.token) {
        config.headers['X-Token'] = getToken() // 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改
      }
      return config
}, error => {
    Promise.reject(error)
})

service.interceptors.response.use(response => response, error => {
    return Promise.reject(error)
})

export default service